package com.romotc.qqrobot.bean;

import java.io.IOException;
import java.util.List;

import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;

import com.romotc.joyin.bean.Customer;
import com.romotc.joyin.bean.CustomerService;
import com.romotc.joyin.bean.MemberCustService;
import com.romotc.json.tools.Jackson;
import com.romotc.qqrobot.webqq.bean.Get_friend_info2_ResponseBody;
import com.romotc.qqrobot.webqq.bean.Get_friend_info2_ResponseBody_result;

public class QQInfoFromQQLogedinService {

	
	/**
	 * //查询客服人员资料并组织成QQInfoFromQQlogedIn格式
	 * @param custServiceId 客服人员Id
	 * @return
	 */
	public static QQInfoFromQQLogedin qryQqMemCustInfo(long custServiceId) {
		// 查询客服对象
		MemberCustService memCustServ = MemberCustServiceService
			.qryMemberCustServiceById(custServiceId);
		
		if(memCustServ == null)
			return null;
		
		Get_friend_info2_ResponseBody friendInfo = new Get_friend_info2_ResponseBody();
		Get_friend_info2_ResponseBody_result result = new Get_friend_info2_ResponseBody_result();
		result.setNick(memCustServ.getCustServiceName());
		result.setMobile(memCustServ.getTel());
		result.setUin(memCustServ.getId());
		friendInfo.setResult(result);
		
		//组织QQInfoFromQQLogedin
		QQInfoFromQQLogedin qqInfo = new QQInfoFromQQLogedin();
		String info;
		try {
			info = Jackson.getObjectMaper().writeValueAsString(friendInfo);
			qqInfo.setInfo(info);
			
			return qqInfo;
		} catch (JsonGenerationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (JsonMappingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return null;
	}

	
	/**
	 * //查询客户信息 并组织成QQInfoFromQQlogedIn格式
	 * @param customerId
	 * @return
	 */
	public static QQInfoFromQQLogedin qryCustQQInfo(long customerId) {
		//客户
		Customer cust = CustomerService.qryCustomerById(customerId);
		if(cust == null)
			return null;

		Get_friend_info2_ResponseBody friendInfo = new Get_friend_info2_ResponseBody();
		Get_friend_info2_ResponseBody_result result = new Get_friend_info2_ResponseBody_result();
		result.setNick(cust.getCustName());
		result.setMobile(cust.getTel());
		result.setUin(-customerId);
		friendInfo.setResult(result);
		
		//组织QQInfoFromQQLogedin
		QQInfoFromQQLogedin qqInfo = new QQInfoFromQQLogedin();
		String info;
		try {
			info = Jackson.getObjectMaper().writeValueAsString(friendInfo);
			qqInfo.setInfo(info);
			
			return qqInfo;
		} catch (JsonGenerationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (JsonMappingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

}
